package com.ht.base.system.biz.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ht.base.system.common.pojo.qto.SysRoleQTO;
import com.ht.base.system.dao.dao.SysRoleDao;
import com.ht.base.system.dao.domain.SysRoleDO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
public class SysRoleMapper extends ServiceImpl<SysRoleDao, SysRoleDO> {
    @Resource
    private SysRoleDao sysRoleDao;

    public int insetRole(SysRoleDO record) {
        record.setCreateTime(new Date());
        return sysRoleDao.insert(record);
    }

    public int updateRoleById(SysRoleDO update) {
        update.setUpdateTime(new Date());
        return sysRoleDao.updateById(update);
    }

    public int deleteByRoleId(Long sysRoleId) {
        return sysRoleDao.deleteById(sysRoleId);
    }

    public Integer countByCondition(SysRoleDO count) {
        LambdaQueryWrapper<SysRoleDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(count.getRoleKey()), SysRoleDO::getRoleKey, count.getRoleKey());
        wrapper.eq(StringUtils.isNotEmpty(count.getRoleName()), SysRoleDO::getRoleName, count.getRoleName());
        return sysRoleDao.selectCount(wrapper);
    }

    public SysRoleDO findById(Long id) {
        return sysRoleDao.findById(id);
    }

    public List<SysRoleDO> findByCondition(SysRoleDO record) {
        return sysRoleDao.findByCondition(record);
    }

    public Integer findForPageCount(SysRoleQTO qto) {
        return sysRoleDao.findForPageCount(qto);
    }

    public List<SysRoleDO> findForPage(SysRoleQTO qto) {
        return sysRoleDao.findForPage(qto);
    }
}
